package Persistencia;

import Complementos.Conexion_BD;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

public class DienteDAO {

    Conexion_BD co=new Conexion_BD();
    ResultSet rs = null;
    CallableStatement cs=null;


    public void actualizar(String codOdontograma,String nropieza,String ladoizq,String ladoder,String centro,String superior,String inferior){
        try {
            co.Conectar();
            co.getCn().setAutoCommit(false);
            //Llamamos el Store Procedure 
            cs = co.getCn().prepareCall("{CALL usp_actualizar_estado_diente(?,?,?,?,?,?,?)}");
            cs.setString(1, codOdontograma);
            cs.setInt(2, Integer.parseInt(nropieza));
            cs.setString(3, ladoizq);
            cs.setString(4, ladoder);
            cs.setString(5, centro);
            cs.setString(6, superior);
            cs.setString(7, inferior);
            cs.executeUpdate();
            co.getCn().commit();
            
            
            
            
            
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(DienteDAO.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(DienteDAO.class.getName()).log(Level.SEVERE, null, ex);
        }

        
        try {
            co.Desconectar();
        } catch (Exception ex) {
            Logger.getLogger(DienteDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
   
    } //Fin_ActualizarOdontograma


/*
    public void guardarFoto(String id, String ruta) {

        try {
            //Connection connection = DriverManager.getConnection("jdbc:odbc:Sonrisas");
            //Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            co.Conectar();
            cs = co.getCn().prepareCall("{CALL usp_registrar_fotopaciente (?,?)}");

            // PreparedStatement ps = connection.prepareStatement("insert into FOTO_PACIENTE (codpaciente, foto) values (? , ?)");
            
                FileInputStream fis = null;
                try {
                    co.getCn().setAutoCommit(false);
                    cs.setString(1, id);
                    File file = new File(ruta);
                    fis = new FileInputStream(file);

                    cs.setBlob(2, fis, (int) file.length());
                    //      cs.setBinaryStream(2, fis, (int) file.length());

                    cs.setBlob(2, fis, (int)file.length());
                    //cs.setBinaryStream(2, fis, (int) file.length());

                    cs.executeUpdate();
                    co.getCn().commit();
                    System.out.println("Ingreso foto");
                } catch (FileNotFoundException ex) {
                    Logger.getLogger(FotoPacienteDAO.class.getName()).log(Level.SEVERE, null, ex);
                } catch (SQLException es) {
                    co.getCn().rollback();
                    cs.close();
                } finally {
                    try {
                        co.getCn().setAutoCommit(true);
                        fis.close();
                        co.Desconectar();
                    } catch (Exception ex) {
                        Logger.getLogger(PersonaDAO.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(FotoPacienteDAO.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException se) {
            System.out.println("ERROR: " + se.getMessage());
        }
    }
*/
   
    public Vector<Vector> listarTodos(String codigo){
        Vector<Vector> v = new Vector<Vector>();
        try {
            
            String query = "select * from odontograma_beta where idOdontograma = '" + codigo + "'";
            co.Conectar();
            rs = co.Consultar(query);
            if (rs.first()) {
                while (!rs.isAfterLast()) {
                    Vector registro = new Vector();
                    registro.add(rs.getString(2));
                    registro.add(rs.getString(3));
                    registro.add(rs.getString(4));
                    registro.add(rs.getString(5));
                    registro.add(rs.getString(6));
                    registro.add(rs.getString(7));
                    v.add(registro);
                    rs.next();
                }
            }
            
            

        } catch (ClassNotFoundException ex) {
            Logger.getLogger(DienteDAO.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(DienteDAO.class.getName()).log(Level.SEVERE, null, ex);

        }


        try {
            co.Desconectar();
        } catch (Exception ex) {
            Logger.getLogger(DienteDAO.class.getName()).log(Level.SEVERE, null, ex);
        }

            return v;
    }
    
    
    
    
    
    
    
    

}
